<template>
  <el-card class="tableBox">
    <template #header>
      <div class="card-header">
        <span>角色列表</span>
        <el-button class="button" type="primary">新增角色</el-button>
      </div>
    </template>
    <el-table :data="tableData" border style="width: 100%" v-loading="loading">
      <el-table-column prop="manageId" label="ID" />
      <el-table-column prop="managerPhone" label="电话号码" />
      <el-table-column prop="managerAccoent" label="账号" />
      <el-table-column prop="managerPassword" label="密码" />
      <!--      <el-table-column fixed="right" label="操作" width="120px">-->
      <!--        <template #default="scope">-->
      <!--          <el-button type="danger" @click.prevent="deleteRow(scope.$index)">-->
      <!--            删除-->
      <!--          </el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <div class="paginationBox">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 20, 30]"
        :small="small"
        :disabled="disabled"
        :background="background"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useAdminStoreHook } from "@/store/modules/admin";

const currentPage = ref(1);
const pageSize = ref(10);
const small = ref(false);
const background = ref(false);
const disabled = ref(false);

const handleSizeChange = (val: number) => {
  pageSize.value = val;
  loadingInfo();
};
const handleCurrentChange = (val: number) => {
  currentPage.value = val;
  loadingInfo();
};

// 获取列表信息
const total = ref(100);
let loading = true;
const adminStore = useAdminStoreHook();
const tableData = ref([]);
async function loadingInfo() {
  await adminStore.getAdminInfo(currentPage.value, pageSize.value);
  loading = false;
  total.value = adminStore.total;
  tableData.value = adminStore.adminList;
}
loadingInfo();
</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tableBox {
  margin-top: 20px;
}

.paginationBox {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
}
</style>
